<template>
  <div>
    <el-generate-form ref="generateFormRef" v-model="formData" :data="widgetForm" >
      </el-generate-form>
    <el-button type="primary" @click="handleSubmit">提交</el-button>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch, onMounted } from 'vue'
import widgetForm from './widgetForm'

const generateFormRef = ref()
const formData = ref()

const handleSubmit = () => {
  generateFormRef.value
    .getData()
    .then((data) => {
      console.log(data, '表单数据')
    })
    .catch((err) => {
      console.log(err)
    })
}
onMounted(() => {
  generateFormRef.value.remove('prectentRate')
})

watch(
  () => formData.value,
  (val) => {
    if (!generateFormRef.value) return
    if (val.radio_d7d6becfb7e542c68b6ea92b8b94be2d === '1') {
      generateFormRef.value.remove('prectentRate')
      generateFormRef.value.add('rate_f3090728906a4f03aafab03d2e1628d9')
    } else {
      generateFormRef.value.add('prectentRate')
      generateFormRef.value.remove('rate_f3090728906a4f03aafab03d2e1628d9')
    }
  },
  { deep: true }
)
</script>
